package net.arvin.model;

public class Time {
	public int year;
	public int month;
	public int day;
	public int hour;
	public int minute;
	public int second;
	public String time;

	public void setTime(String time) {
		this.time = time;
	}

	public String getTime() {
		return this.time;
	}
	
	public String getMonth(String time){
		Time time1 = new Time();
		time1.toTime(time);
		return time1.month+"";
	} 

	public void toTime(String time) {
		setTime(time);
		year = Integer.valueOf(time.substring(0, time.indexOf("-")));
		month = Integer.valueOf(time.substring(time.indexOf("-") + 1,
				time.lastIndexOf("-")));
		day = Integer.valueOf(time.substring(time.lastIndexOf("-") + 1,
				time.indexOf(" ")));
		hour = Integer.valueOf(time.substring(time.indexOf(" ") + 1,
				time.indexOf(":")));
		minute = Integer.valueOf(time.substring(time.indexOf(":") + 1,
				time.lastIndexOf(":")));
		second = Integer.valueOf(time.substring(time.lastIndexOf(":") + 1));
	}

	public static boolean isTime1ThanTime2(Time t1, Time t2) {
		if (t1.year > t2.year) {
			return true;
		}
		if (t1.year < t2.year) {
			return false;
		}
		if (t1.year == t2.year) {
			if (t1.month > t2.month) {
				return true;
			}
			if (t1.month < t2.month) {
				return false;
			}
			if (t1.month == t2.month) {
				if (t1.day > t2.day) {
					return true;
				}
				if (t1.day < t2.day) {
					return false;
				}
				if (t1.day == t2.day) {
					if (t1.hour > t2.hour) {
						return true;
					}
					if (t1.hour < t2.hour) {
						return false;
					}
					if (t1.hour == t2.hour) {
						if (t1.minute > t2.minute) {
							return true;
						}
						if (t1.minute < t2.minute) {
							return false;
						}
						if (t1.minute == t2.minute) {
							if (t1.second >= t2.second) {
								return true;
							} else {
								return false;
							}
						}
					}
				}
			}
		}
		return true;
	}

	@Override
	public String toString() {
		return "Time [year=" + year + ", month=" + month + ", day=" + day
				+ ", hour=" + hour + ", minute=" + minute + ", second="
				+ second + "]";
	}
}
